#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

#define FOR(i,a,n) for(int i=a;i<int(n);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int a[50500],*ap[50500];
typedef long long lld;
class BitInteger
{
public:
  static  const int mod = 10000000;
  vector<int> v;
  BitInteger(int n)
  {
      v.push_back(n%mod);
      if(n>=mod) v.push_back(n/mod);
  }
  void add(lld n)
  {
      int vi = 0;
      while(n)
      {
          int t = n%mod;
          v[vi++]+=t;
          n/=mod;
      }
      REP(i,v.size())
      {
          if(v[i]>=mod)
          {
              if(i==v.size()-1) v.push_back(1);
              else
              {
                  v[i+1]++;
              }
              v[i]%=mod;
          }
      }
  }
  void print()
  {
      printf("%d",v.back());
      for(int i=v.size()-2;i>=0;i--)
      {
          printf("%07d",v[i]);
      }
  }
};
class Tree
{
public:
   lld *ca;
   int n;
   Tree(int ni=50500)
   {
       ca = new lld[50500];
       n=ni;
       fill(ca,ca+n,0);
   }
   ~Tree()
   {
       delete(ca);
   }
   inline int LowBit(int pos)
   {
       return pos&(-pos);
   }
   void insert(int pos,lld val)
   {
       while(pos<=n) ca[pos]+=val,pos+=LowBit(pos);
   }
   lld query(int lb,int rb)
   {
       if(lb!=1) return query(1,rb)-query(1,lb-1);
       lld ans = 0;
       while(rb>=1) ans+=ca[rb],rb-=LowBit(rb);
       return ans;
   }
};
bool cmp(int *pa,int *pb)
{
    return *pa<*pb;
}
int main()
{
    int n;
    while(cin>>n)
    {
        REP(i,n) scanf("%d",a+i),ap[i]=a+i;
        sort(ap,ap+n,cmp);
        int p=1;
        REP(i,n-1)
        if(*ap[i]==*ap[i+1]) *ap[i]=p;
        else *ap[i] = p++;
        *ap[n-1]=p;
        Tree tr[6];
        BitInteger ans(0);
        REP(i,n) if(a[i]>=1&&a[i]<=n)
        {
            for(int k=4;k>=1;--k)
            {
                lld t=k==1?1:tr[k-1].query(1,a[i]-1);
                tr[k].insert(a[i],t);
            }
            ans.add(tr[4].query(1,a[i]-1));
        }
        ans.print();
        cout<<endl;
    }
    return 0;
}
